{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-02-27T05:09:13.406911Z",
     "start_time": "2024-02-27T05:09:12.975080Z"
    }
   },
   "outputs": [],
   "source": [
    "import os\n",
    "from openai import AzureOpenAI\n",
    "from agency_swarm import set_openai_client\n",
    "\n",
    "client = AzureOpenAI(\n",
    "    api_key=os.getenv(\"AZURE_OPENAI_KEY\"),\n",
    "    # https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#rest-api-versioning\n",
    "    api_version=\"2024-02-15-preview\",\n",
    "    # https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/create-resource?pivots=web-portal#create-a-resource\n",
    "    azure_endpoint=os.getenv(\"AZURE_ENDPOINT\"),\n",
    "    timeout=5,\n",
    "    max_retries=5,\n",
    ")\n",
    "\n",
    "set_openai_client(client)"
   ]
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "from agency_swarm import Agent\n",
    "\n",
    "agent1 = Agent(name=\"agent1\", description=\"I am a simple agent\", model='assistants-test')\n",
    "\n",
    "ceo = Agent(name=\"ceo\", description=\"I am the CEO\", model='assistants-test')"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-27T05:09:14.574852Z",
     "start_time": "2024-02-27T05:09:14.570556Z"
    }
   },
   "id": "6ed63cac3adfd958",
   "execution_count": 2
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "from agency_swarm import Agency\n",
    "\n",
    "agency = Agency([ceo, [ceo, agent1]])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-27T05:09:17.184056Z",
     "start_time": "2024-02-27T05:09:15.516931Z"
    }
   },
   "id": "8d34677515d0b414",
   "execution_count": 3
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "THREAD:[ user -> ceo ]: URL https://platform.openai.com/playground?assistant=asst_mhCaCa34Pl0TwEqoWjJPZp6S&mode=assistant&thread=thread_PKH38vf5cqSmZwvnIHjCJFmC\n",
      "THREAD:[ ceo -> agent1 ]: URL https://platform.openai.com/playground?assistant=asst_me5PZEqSAJPOdzPbcozWG6ZD&mode=assistant&thread=thread_MHl3BosNdC5tvzdNGMhCFhhB\n"
     ]
    }
   ],
   "source": [
    "response = agency.get_completion(\"Say hi to agent1. Let me know his response.\", yield_messages=False)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-27T05:09:50.392702Z",
     "start_time": "2024-02-27T05:09:39.272522Z"
    }
   },
   "id": "49d28043d85f925c",
   "execution_count": 6
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Agent1 says, \"Hello! How can I assist you today?\"\n"
     ]
    }
   ],
   "source": [
    "print(response)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-27T05:09:50.398665Z",
     "start_time": "2024-02-27T05:09:50.394964Z"
    }
   },
   "id": "57d25ceeb2860261",
   "execution_count": 7
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
